<#--
Name: 数据列表模板
Desc:数据列表模板

本模板需要通过2次解析才能得到最终的Html
第一次解析：
*************************************************************
*************************************************************
*数据模型:****************************************************
*************************************************************
*************************************************************

tbarTitle：Tool Bar 的标题

********************************************
conditionFields:条件字段
--joinType：  条件联合类型
--name：  列名
--name：完全指定名
--operate：条件类型: =|>=|<=|….
--comment：注释
--type：  类型
--value：值
--valueFrom：值来源

************************************************************
displayFields：显示字段
--name：列名
--name：完全指定名
--label：别名
--index：索引
--comment：注释
--type：类型

******************************************************
tableIdCode:Table ID Code

**************************************************
displayId: 自定义显示的ID

*************************************************
pageURL：当前页面的URL

searchFormURL：搜索表单的Action


sortField：当前排序字段

orderSeq：当前的排序类型

***********************************************
pkcols:主键列

deleteBaseURL：删除一行数据的BaseURL
editBaseURL：编辑一行数据的BaseURL
-->


<#setting number_format="#">
<#assign displayFields=bpmDataTemplate.displayField?eval>
<#assign conditionFields=bpmDataTemplate.conditionField?eval>
<#assign filterFields=bpmDataTemplate.filterField?eval>
<#assign manageFields=bpmDataTemplate.manageField?eval>

<#noparse>
    <#setting number_format="#">
    <#assign displayFields=bpmDataTemplate.displayField?eval>
    <#assign conditionFields=bpmDataTemplate.conditionField?eval>
    <#assign filterFields=bpmDataTemplate.filterField?eval>
    <#assign manageFields=bpmDataTemplate.manageField?eval>
</#noparse>
<#--日期选择器 -->
<#macro genQueryDate field>
    <#switch field.qt>
        <#case "D">
            <input type="text" name="Q_${field.na}_D" readonly="readonly"  class="layui-input filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_D'<#noparse>]}"</#noparse>  />
            <#break>
        <#case "DL">
            <input type="text" name="Q_${field.na}_DL" readonly="readonly"  class="layui-input start_time filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_DL'<#noparse>]}"</#noparse> />
            <#break>
        <#case "DG">
            <input type="text" name="Q_${field.na}_DG"  readonly="readonly" class="layui-input filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_DG'<#noparse>]}"</#noparse>  />
            <#break>
        <#case "DR">
            <input type="text" name="Q_begin${field.na}_DL" readonly="readonly" placeholder="开始时间" class="layui-input start_time filter-value" value="<#noparse>${param[</#noparse>'Q_begin${field.na}_DL'<#noparse>]}"</#noparse>  />
            <span style="float:left;margin-left: 25px;margin-right: 23px;margin-top: 2px;">至</span>
            <input type="text" name="Q_end${field.na}_DG" readonly="readonly" placeholder="结束时间" class="layui-input end_time filter-value" value="<#noparse>${param[</#noparse>'Q_end${field.na}_DG'<#noparse>]}"</#noparse> />
            <#break>
        <#default>
            <input type="text" name="Q_${field.na}_${field.qt}" class="layui-input filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_${field.qt}'<#noparse>]}"</#noparse> />
            <#break>
    </#switch>
</#macro>
<#--用户选择器 -->
<#macro genQuerySelector field>
    <#switch field.ct>
        <#case "4"><#--用户单选选择器 -->
            <input type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID"  value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" value="选择" onclick="selectUser(this);" style="margin: 4px;width:48px;">
            <#break>
        <#case "5"><#--角色多选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" onclick="__Selector__.selectRole({self:this});" value="选择">
            <#break>
        <#case "6"><#--组织多选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button"  class="layui-btn layui-btn-sm" onclick="__Selector__.selectOrg({self:this});" value="选择">
            <#break>
        <#case "7"><#--岗位多选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" onclick="__Selector__.selectPos({self:this});" value="选择">
            <#break>
        <#case "8"><#--人员多选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button"  class="layui-btn layui-btn-sm" onclick="__Selector__.selectUser({self:this});" value="选择">
            <#break>
        <#case "17"><#--角色单选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" value="选择" onclick="selectRole(this)" style="margin: 4px;width:48px;">
            <#break>
        <#case "18"><#--组织单选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" value="选择" onclick="selectOrg(this)" style="margin: 4px;width:48px;">
            <#break>
        <#case "19"><#--岗位单选选择器 -->
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" onclick="__Selector__.selectPos({self:this});" value="选择">
            <#break>
        <#default>
            <input  type="hidden" name="Q_${field.na}ID_S" class="layui-input filter-value" id="${field.na}ID" value="<#noparse>${param[</#noparse>'Q_${field.na}ID_L'<#noparse>]}"</#noparse>>
            <input type="text" readonly="readonly" class="layui-input filter-value" name="Q_${field.na}~_SL" id="${field.na}" value="<#noparse>${param[</#noparse>'Q_${field.na}~_SL'<#noparse>]}"</#noparse>>
            <input type="button" class="layui-btn layui-btn-sm" onclick="selectUser(this);" value="选择">
            <#break>
    </#switch>
</#macro>
<#-- 选择器 -->
<#macro genQuerySelect field formatData>
    <select  name="Q_${field.na}_${field.qt}" class="filter-value">
<option value="">全部</option>
    <#if formatData?if_exists >
        <#list formatData?keys as key>
            <option value="${key}"  <#noparse><#if param['</#noparse>Q_${field.na}_${field.qt}'] == '${key}'>selected<#noparse></#if></#noparse>>${formatData[key]}</option>
        </#list>
    </#if>
    </select>
</#macro>


<#--生成查询条件宏 -->
<#macro genCondition field formatData>
    <#if field.vf=="1" >
        <label class="layui-form-label">${field.cm}</label>
        <#switch field.ct>
            <#case "1">
                <#if field.ty == 'number'>
                    <input type="text" name="Q_${field.na}_${field.qt}" class="layui-input filter-value"  lay-verify="number" value="<#noparse>${param[</#noparse>'Q_${field.na}_${field.qt}'<#noparse>]}"</#noparse> />
                <#else>
                    <input type="text" name="Q_${field.na}_${field.qt}" class="layui-input filter-value"  value="<#noparse>${param[</#noparse>'Q_${field.na}_${field.qt}'<#noparse>]}"</#noparse>  />
                </#if>

                <#break>
            <#-- 选择器 -->
            <#case "4">
            <#case "5">
            <#case "6">
            <#case "7">
            <#case "8">
            <#case "17">
            <#case "18">
            <#case "19">
                <@genQuerySelector field=field/>
                <#break>
            <#case "15"><#--日期选择器 -->
                <@genQueryDate field=field/>
                <#break>
            <#case "11"><#--下拉选项-->
                <#if formatData[field.na]?if_exists >
                    <@genQuerySelect field=field formatData=formatData[field.na]/>
                <#else>
                    <input type="text" name="Q_${field.na}_${field.qt}" class="layui-input filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_${field.qt}'<#noparse>]}"</#noparse> />
                </#if>
                <#break>
            <#case "3"><#--数据字典-->
                <#if formatData[field.na]?if_exists >
                    <@genQuerySelect field=field formatData=formatData[field.na]/>
                <#else>
                    <input type="text" name="Q_${field.na}_${field.qt}" class="layui-input filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_${field.qt}'<#noparse>]}"</#noparse> />
                </#if>
                <#break>
            <#default>
                <input type="text" name="Q_${field.na}_${field.qt}" class="layui-input filter-value" value="<#noparse>${param[</#noparse>'Q_${field.na}_${field.qt}'<#noparse>]}"</#noparse> />
                <#break>
        </#switch>
    </#if>
</#macro>

<#noparse>
    <#--管理列-->
    <#macro genManage manage managePermission actionUrl data>
    <#--编辑-->
    <#if manage.name == 'edit' >
    <#if managePermission.edit>
    {{#  if(d.BUS_STATUS=='0'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">${manage.desc}</a>
    {{#  } }}
    </#if>
    <#--删除-->
    <#elseif manage.name == 'del' >
    <#if managePermission.del>
    {{#  if(d.BUS_STATUS=='0'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">${manage.desc}</a>
    {{#  } }}
    </#if>
    <#--明细-->
    <#elseif manage.name == 'detail' >
    <#if managePermission.detail>
    <a class="layui-btn layui-btn-xs" lay-event="detail">${manage.desc}</a>
    </#if>
    <#--启动-->
    <#elseif manage.name == 'start' >
    <#if managePermission.start>
    <#if actionUrl.start?if_exists>
    <#assign isStart= "false" >
    <#else>
    <#assign isStart= "true" >
    </#if>
    <#if data.BUS_STATUS==0>
    <a class="layui-btn layui-btn-xs" lay-event="start">${manage.desc}</a>
    </#if>
    </#if>
    <#elseif manage.name == 'reStart' >
    <#if managePermission.reStart>
    <#if actionUrl.reStart?if_exists>
    <#assign isStart= "false" >
    <#else>
    <#assign isStart= "true" >
    </#if>
    <#if (data.BUS_STATUS==2 || data.BUS_STATUS==3) >
    <a class="layui-btn layui-btn-xs" action="${actionUrl.reStart}&relRunId=${data.BUS_FLOW_RUNID}"  lay-event="reStart" href="javascript:;">${manage.desc}</a>
    </#if>
    </#if>
    </#if>
    </#macro>
    <#--顶部按钮-->



    <#macro genToolBar manage managePermission actionUrl>
    <#--新增-->
    <#if manage.name == 'add' >
    <#if managePermission.add>
    <a class="layui-btn layui-btn-sm"  lay-event="add"> <i class="layui-icon layui-icon-add-1"></i>${manage.desc}</a>
    </#if>
    <#--批量删除-->
    <#elseif  manage.name == 'batchDel' >
    <#if managePermission.batchDel>
    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel"> <i class="layui-icon layui-icon-delete"></i>${manage.desc}</a>
    </#if>
    <#--导出-->
    <#elseif manage.name == 'export' >
    <#if managePermission.export>
    <a class="layui-btn layui-btn-sm" lay-event="export"><i class="layui-icon layui-icon-export"></i>${manage.desc}</a>
    </#if>
    <#--导入-->
    <#elseif manage.name == 'import' >
    <#if managePermission.import>
    <a class="layui-btn layui-btn-sm" lay-event="import"><i class="layui-icon layui-icon-download-circle"></i>${manage.desc}</a>
    </#if>
    <#--打印-->
    <#elseif manage.name == 'print' >
    <#if managePermission.print>
    <a class="layui-btn layui-btn-sm" action="${actionUrl.print}"  onclick=""  href="javascript:;"><i class="layui-icon layui-icon-print"></i>${manage.desc}</a>
    </#if>
    <#--启动-->
    <#elseif manage.name == 'start' >
    <#if managePermission.start>
    <#if actionUrl.start?if_exists>
    <#assign isStart= "false" >
    <#else>
    <#assign isStart= "true" >
    </#if>
    <a class="layui-btn layui-btn-sm" lay-event="start"><i class="layui-icon layui-icon-play"></i>${manage.desc}</a>
    </#if>
    </#if>
    </#macro>



</#noparse>
<#--过滤条件-->
<#noparse><#if filterFields??>
    <div class="panel" ajax="ajax"  displayId="${bpmDataTemplate.id}" filterKey="${filterKey}" style="padding:0 10px 10px 10px;margin-top:-10px;">
        <#if filterFields?size gt 1>
        <div class="layui-tab layui-tab-brief">
            <ul style="left: 0px;" class="layui-tab-title">
                <#list filterFields as field>
                <li tabid="${field.key}" onclick="filterPage('${field.key}')" <#if field.key ==filterKey> class="layui-this"</#if> > ${field.desc}</li>
        </#list>
        </ul>
    </div>
    </div>
    </#if>
</#noparse>
<#--查询头-->
<script type="text/html" id="HeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <#if hasCondition>
                <a class="layui-btn layui-btn-sm" lay-event="query"> <i class="layui-icon layui-icon-search"></i>查询</a>
                <a class="layui-btn layui-btn-sm" lay-event="reset">  <i class="layui-icon layui-icon-refresh"></i>重置</a>
            </#if>
            <#noparse><#list manageFields as manage>
            <@genToolBar manage=manage managePermission=managePermission actionUrl=actionUrl />
        </#list></#noparse>
        </div>
    <#if hasCondition >
    <#--查询条件-->
        <#if conditionFields?if_exists>
            <form class="layui-form onlineForm"  style="margin-top:10px" lay-filter="conditionForm" onsubmit="return false">
                <div class="table-top-filter">

            <#list conditionFields as field>
                <div class="table-filter-alone">
                <@genCondition field=field formatData=formatData/>
                </div>
            </#list>
                </div>
            </form>
        </#if>
    </#if>
    </div>
</script>
<#--表头-->
<table class="layui-table" lay-filter="templateTable"  id="templateTable">

<#--表体-->
    <script type="text/html" id="barManage">
        <#noparse><#list manageFields as manage>
            <@genManage manage=manage managePermission=managePermission actionUrl=actionUrl data=data/>
            </#list></#noparse>
    </script>

</table>
<#noparse>
    <script>
        var  setter,table ;
        var common;
        var laydate;
        var displayField = JSON.parse('${bpmDataTemplate.displayField}');
        var paramStr = '${paramStr}';
        var array = [];
        var permission = JSON.parse('${permissionStr}');
        var barManage = { fixed: 'right',align: 'center',title: '管理', toolbar: '#barManage'};
        var checkboxField = {type: 'checkbox', fixed: 'left'};
        array.push(checkboxField);
        for(var i =0; i<displayField.length;i++){
            var json ={};
            var fieldName = displayField[i].name;
            json.field = fieldName;
            json.title = displayField[i].desc;
            json.align="center";
            if(permission[fieldName]){
                array.push(json);
            }
        }
        array.push(barManage);

        var tableRender;


        var filterKey;
        function filterPage(key){
            filterKey=key;
            loadOnLineTable("full-80",{__filterKey__:key});
            reflashDateForm();
        }

        function selectUser(ele){
            var selectUserName=$(ele).prev();
            var userSelectorWin;
            var body;
            var selectUserNameId=selectUserName.prev();
            layer.open({
                type: 2
                , title: '人员选择器'
                , area: ['980px', '630px']
                , btn: ["保存", "取消", "撤销"]
                , resize: false
                , content:serverPath.formPath + setter.sysLinkPath + 'dialog/view/singleSysUserDialog?selectUserId='+selectUserNameId.val()
                ,success: function(layero, index){
                    body = layer.getChildFrame('body', index);
                    userSelectorWin = window[layero.find('iframe')[0]['name']];
                },
                yes: function (index, layero) {
                    userSelectorWin.saveData(index);
                    var theUserList = body.find("input[name=selectUser]").val();
                    if (theUserList) {
                        var item = JSON.parse(theUserList);
                        selectUserName.val(item.fullName);
                        selectUserNameId.val(item.userId);
                    } else {
                        selectUserName.val("");
                        selectUserNameId.val("");
                    }
                    layer.close(index);
                },
                btn3: function (index, layero) {
                    userSelectorWin.cancelData(index);
                    return false //开启该代码可禁止点击该按钮关闭
                }
            });
        }
        function selectRole(ele){
            var selectRoleName=$(ele).prev();
            var roleSelectorWin;
            var body;
            var selectRoleNameId=selectRoleName.prev();
            layer.open({
                type: 2
                , title: '角色选择器'
                , area: ['980px', '630px']
                , btn: ["保存", "取消", "撤销"]
                , resize: false
                , content:serverPath.formPath + setter.sysLinkPath + 'dialog/view/singleSysRoleDialog?selectRoleId='+selectRoleNameId.val()
                ,success: function(layero, index){
                    body = layer.getChildFrame('body',index);
                    roleSelectorWin = window[layero.find('iframe')[0]['name']];
                },
                yes: function (index, layero) {
                    roleSelectorWin.saveData(index);
                    var theRoleList = body.find("input[name=selectRole]").val();
                    if (theRoleList) {
                        var item = JSON.parse(theRoleList);
                        selectRoleName.val(item.roleName);
                        selectRoleNameId.val(item.roleId);
                    } else {
                        selectRoleName.val("");
                        selectRoleNameId.val("");
                    }
                    layer.close(index);
                },
                btn3: function (index, layero) {
                    roleSelectorWin.cancelData(index);
                    return false //开启该代码可禁止点击该按钮关闭
                }
            });
        }
        function selectOrg(ele){
            var selectOrgName=$(ele).prev();
            var orgSelectorWin;
            var body;
            var selectOrgNameId=selectOrgName.prev();
            layer.open({
                type: 2
                , title: '组织选择器'
                , area: ['980px', '630px']
                , btn: ["保存", "取消", "撤销"]
                , resize: false
                , content: serverPath.formPath + setter.sysLinkPath + 'dialog/view/singleSysOrgDialog?selectOrgId='+selectOrgNameId.val()
                ,success: function(layero, index){
                    body = layer.getChildFrame('body',index);
                    orgSelectorWin = window[layero.find('iframe')[0]['name']];
                },
                yes: function (index, layero) {
                    orgSelectorWin.saveData(index);
                    var theOrgList = body.find("input[name=selectOrg]").val();
                    if (theOrgList) {
                        var item = JSON.parse(theOrgList);
                        selectOrgName.val(item.name);
                        selectOrgNameId.val(item.orgId);
                    } else {
                        selectOrgName.val("");
                        selectOrgNameId.val("");
                    }
                    layer.close(index);
                },
                btn3: function (index, layero) {
                    orgSelectorWin.cancelData(index);
                    return false //开启该代码可禁止点击该按钮关闭
                }
            });
        }
        var tableLimit='${bpmDataTemplate.pageSize}';
        //加载表格
        function loadOnLineTable(h,whereInfo){
            //多个过滤条件时候 表格高度重新赋值
            if($(".panel .layui-tab.layui-tab-brief ul>li").length>0 && whereInfo == ''){
                var filterValue = $(".panel .layui-tab.layui-tab-brief>li").attr("tabid");
                whereInfo= {__filterKey__:filterValue};
                h="full-80";
            }
            tableRender =  table.render({
                elem: '#templateTable',
                url:serverPath.formPath + setter.formLinkPath + 'dataTemplate/queryDataList'+paramStr,
                autoSort: false,
                cols: [array],
                height:h,
                defaultToolbar: ['filter', 'print'],
                toolbar: '#HeaderToolsBar',
                page: true,
                limits:[5,10,15,20,50],
                limit:tableLimit,
                where:whereInfo,
                done: function () {
                    common.tableSelectCon('.ccpui-enterSel .layui-form input', 'a[lay-event=query]', '.ccpui-enterSel')
                }
            });
        }

        function reflashDateForm(){
            var dateTimeStartLen = $(".start_time");
            for(var i=0;i<dateTimeStartLen.length;i++){
                laydate.render({
                    elem: dateTimeStartLen[i] //指定元素
                    ,type: 'date'
                });
            }
            var dateTimeEndLen = $(".end_time");
            for(var j=0;j<dateTimeEndLen.length;j++){
                laydate.render({
                    elem: dateTimeEndLen[j] //指定元素
                    ,type: 'date'
                });
            }
        }

        layui.use(['table','totalFilter','layer', 'jquery', 'form','setter', 'tree','commons','common','laydate'], function(){
            var  commons = layui.commons,
                    $ = layui.jquery,
                    totalFilter = layui.totalFilter;
            laydate = layui.laydate;
            common = layui.common;
            table = layui.table;
            setter = layui.setter;
            var tableH='full-70';
                tableH=commons.tabHeight(tableH);

            //加载表格
            loadOnLineTable(tableH,'');
            totalFilter.init('templateTable');

            //头工具栏事件
            table.on('toolbar(templateTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data; //获取选中行数据
                var isNeedReload=true;
                switch (obj.event) {
                    case 'query':
                        reflashQuery();
                        reflashDateForm();
                        //commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        break;
                    case 'reset':
                        common.tableConditionRender("templateTable","conditionForm",{where:{}},true);
                        reflashDateForm();
                        //commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        break;
                    case 'export':
                        layer.confirm('确定导出吗？', {
                            btn: ['是', '否']
                        }, function (index) {
                            layer.close(index);
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].ID);
                            }
                            var exportIds = ids.join(',');
                            var url = serverPath.formPath + setter.formLinkPath + 'dataTemplate/exportData?alias=${alias}&__exportIds__=' + exportIds+'&__filterKey__='+filterKey;
                            window.location.href = url;
                        });
                        break;
                    case 'add':
                        layer.open({
                            type: 2,
                            area: ['100%', '100%'],
                            title: ['新增'],
                            content: serverPath.formPath + setter.formLinkPath + 'dataTemplate/view/addEdit?formKey=${alias}'
                        });
                        break;
                    case 'batchDel':
                        if (data.length === 0) {
                            layer.msg('请先选择一行数据!');
                            return false;
                        }
                        var batchIds = [];
                        for (var i = 0; i < data.length; i++) {
                            if(data[i].BUS_STATUS=='0'){
                                batchIds.push(data[i].ID);
                            }
                        }
                        if(batchIds.length === 0){
                            layer.msg('与流程绑定的数据不能删除!');
                            return false;
                        }
                        var ids = batchIds.join(',');
                        batchDel(ids);
                        break;
                    case 'import':
                        layer.open({
                            type: 2,
                            area: ['400px', '210px'],
                            title: ['导入'],
                            content:serverPath.formPath + setter.formLinkPath +'dataTemplate/view/import?formKey=${alias}'
                        });
                        break;
                    case "start":
                        var url= serverPath.workflowPath + setter.workflowLinkPath +'task/view/startFlowForm?modelId=${defId}';
                        parent.layer.open({
                            type: 2,
                            area: ['100%', '100%'],
                            title: ['流程启动'],
                            content: url,
                            cancel: function(index, layero){
                                isNeedReload=false;
                            },
                            end:function () {
                                if(isNeedReload){
                                    table.reload('templateTable', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                    totalFilter.init('templateTable');
                                }
                            }
                        });
                        break;
                }
            });


            table.on('tool(templateTable)', function(obj) {
                var data = obj.data, //获得当前行数据
                        layEvent = obj.event; //获得 lay-event 对应的值
                var id = data.ID;
                switch(layEvent){
                    case "del":
                        delFun(data,id);
                        break;
                    case "detail":
                        layer.open({
                            type: 2,
                            area: ['100%', '100%'],
                            title: ['明细'],
                            content: serverPath.formPath + setter.formLinkPath + 'dataTemplate/view/detail?alias=${alias}&id='+id
                        });
                        break;

                    case "edit":
                        layer.open({
                            type: 2,
                            area: ['100%', '100%'],
                            title: ['编辑'],
                            content: serverPath.formPath + setter.formLinkPath + 'dataTemplate/view/addEdit?formKey=${alias}&id='+id
                        });
                        break;
                }
            });
            function delFun(data,id) {
                if (data.length === 0) {
                    layer.msg('请先选择一行数据!');
                } else {
                    layer.confirm('确定删除当前数据吗?', function (index) {
                        layer.close(index);
                        $.ajax({
                            url: serverPath.formPath + setter.formLinkPath + 'dataTemplate/deleteData?alias=${alias}',
                            type: "post",
                            data: {"id":id},
                            dataType: 'json',
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                reflashQuery();
                                reflashDateForm();
                                //commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert(data.msg);
                            }
                        })
                    })
                }
            }
            //批量删除
            function batchDel(ids) {
                layer.confirm('只能删除未绑定流程的数据，确定删除当前数据吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.formPath + setter.formLinkPath + 'dataTemplate/batchDeleteData?alias=${alias}',
                        type: "post",
                        data: {"ids":ids},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery();
                            reflashDateForm();
                            //commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(data.msg);
                        }
                    })
                })
            }
            window.Initialization = function () {
                reflashDateForm();
                //commons.reflashDate({startName:'.start_time',endName:'.end_time'});
            };
            /*刷新时间控件*/
            //commons.reflashDate({startName:'.start_time',endName:'.end_time'});
            reflashDateForm();
            common.tableSort("templateTable",{show:window.Initialization});

            function reflashQuery() {
                common.tableConditionRender("templateTable", "conditionForm", {where: {}}, false,false,tableLimit);
            }
        })
    </script>
</#noparse>
    </div>
<div style="display: none;" id="exportField" >
    <table cellpadding="1" cellspacing="1" class="table-grid table-list">
        <tr>
            <th width="30px"><input id="checkFieldAll" type="checkbox" checked="checked">选择</th>
            <th>字段</th>
        </tr>
        <#list displayFields as field>
            <#noparse><#if permission.</#noparse>${field.name}<#noparse>></#noparse>
            <tr>
                <td><input class="field" type="checkbox" value="${field.name}" name="field" checked="checked"></td>
                <td>${field.desc}</td>
            <tr>
            <#noparse></#if></#noparse>
        </#list>
    </table>
</div>
<form id="exportForm" name="exportForm" method="post" target="download" action="exportData?alias=<#noparse>${alias}</#noparse>.ht" style="display: none;"></form>
    <iframe id="download" name="download" height="0px" width="0px" style="display: none;"></iframe>

<#noparse>
<#else>
<div style="padding:6px 0px 12px 0px;">当前用户没有满足的过滤条件,请设置过滤条件。<div>
</#if>
</#noparse>
<style>
    .onlineForm .layui-form-label{width:auto!important;}
</style>